﻿@using Microsoft.Extensions.Configuration;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    var messagePage = ViewBag.MessagePage as Page<MsSystem.Web.Areas.OA.Model.OaMessageMyList>;
}
<!--左侧导航开始-->
@await Component.InvokeAsync("LeftMenu")

<!--左侧导航结束-->
<!--右侧部分开始-->
<div id="page-wrapper" class="gray-bg dashbard-1">
    <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
                <form role="search" class="navbar-form-custom" method="post">
                    <div class="form-group">
                        <input type="text" placeholder="请输入您需要查找的内容 …" class="form-control" name="top-search" id="top-search">
                    </div>
                </form>
                <!-- 天气信息 -->
                <div id="tp-weather-widget" style="float: left;margin-top: 15px;"></div>
            </div>
            <ul class="nav navbar-top-links navbar-right">
                <li class="dropdown" id="messageTip">
                    <a class="dropdown-toggle count-info" data-toggle="dropdown">
                        <i class="fa fa-envelope"></i> <span class="label label-warning" id="messageTipNums">@messagePage.TotalItems</span>
                    </a>
                    <ul class="dropdown-menu dropdown-messages" id="messageTipContent">
                        @foreach (var item in messagePage.Items)
                        {
                            <li class="m-t-xs">
                                <div class="dropdown-messages-box">
                                    <div class="media-body">
                                        <a data-id="@item.Id" data-type="@item.MsgType" data-link="@item.Link">@item.Title</a>
                                        <small class="text-muted pull-right">@item.CreateTime.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss")</small>
                                    </div>
                                </div>
                            </li>
                            <li class="divider"></li>
                        }
                        <li id="messageTipAll" style="@(messagePage.Items.HasItems() ? "":"display:none")">
                            <div class="text-center link-block">
                                <a class="J_menuItem" href="/OA/Message/MyList"><i class="fa fa-envelope"></i> <strong> 查看所有消息</strong></a>
                            </div>
                        </li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a class="dropdown-toggle" href="javascript:void(0);" id="ms_fullscreen_btn" title="全屏">
                        <i class="fa fa-arrows-alt"></i>
                    </a>
                </li>
                <li class="dropdown hidden-xs">
                    <a class="right-sidebar-toggle" aria-expanded="false">
                        <i class="fa fa-tasks"></i> 主题
                    </a>
                </li>
            </ul>
        </nav>
    </div>
    <div class="row content-tabs">
        <button class="roll-nav roll-left J_tabLeft">
            <i class="fa fa-backward"></i>
        </button>
        <nav class="page-tabs J_menuTabs">
            <div class="page-tabs-content">
                <a href="javascript:;" class="active J_menuTab" data-id="/Home/Default">首页</a>
            </div>
        </nav>
        <button class="roll-nav roll-right J_tabRight">
            <i class="fa fa-forward"></i>
        </button>
        <div class="btn-group roll-nav roll-right">
            <button class="dropdown J_tabClose" data-toggle="dropdown">
                关闭操作<span class="caret"></span>
            </button>
            <ul role="menu" class="dropdown-menu dropdown-menu-right">
                <li class="J_tabShowActive">
                    <a>定位当前选项卡</a>
                </li>
                <li class="divider"></li>
                <li class="J_tabCloseAll">
                    <a>关闭全部选项卡</a>
                </li>
                <li class="J_tabCloseOther">
                    <a>关闭其他选项卡</a>
                </li>
            </ul>
        </div>
        <a href="/sys/user/logout" class="roll-nav roll-right J_tabExit"><i class="fa fa fa-sign-out"></i> 退出</a>
    </div>
    <div class="row J_mainContent" id="content-main">
        <iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="/Home/Default" frameborder="0" data-id="/Home/Default" seamless></iframe>
        <!--内容-->
    </div>

    @await Html.PartialAsync("_LayoutFooter")

    <!--右侧边栏开始-->
    <div id="right-sidebar">
        <div class="sidebar-container">
            <ul class="nav nav-tabs navs-3">
                <li class="active">
                    <a data-toggle="tab" href="#tab-1">
                        <i class="fa fa-gear"></i> 主题
                    </a>
                </li>
                <li class="">
                    <a data-toggle="tab" href="#tab-2">
                        通知
                    </a>
                </li>
                <li>
                    <a data-toggle="tab" href="#tab-3">
                        项目进度
                    </a>
                </li>
            </ul>
            <div class="tab-content">
                <div id="tab-1" class="tab-pane active">
                    <div class="sidebar-title">
                        <h3> <i class="fa fa-comments-o"></i> 主题设置</h3>
                        <small><i class="fa fa-tim"></i> 你可以从这里选择和预览主题的布局和样式，这些设置会被保存在本地，下次打开的时候会直接应用这些设置。</small>
                    </div>
                    <div class="skin-setttings">
                        <div class="title">主题设置</div>
                        <div class="setings-item">
                            <span>收起左侧菜单</span>
                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="collapsemenu" class="onoffswitch-checkbox" id="collapsemenu">
                                    <label class="onoffswitch-label" for="collapsemenu">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="setings-item">
                            <span>固定顶部</span>

                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="fixednavbar" class="onoffswitch-checkbox" id="fixednavbar">
                                    <label class="onoffswitch-label" for="fixednavbar">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="setings-item">
                            <span>
                                固定宽度
                            </span>

                            <div class="switch">
                                <div class="onoffswitch">
                                    <input type="checkbox" name="boxedlayout" class="onoffswitch-checkbox" id="boxedlayout">
                                    <label class="onoffswitch-label" for="boxedlayout">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="title">皮肤选择</div>
                        <div class="setings-item default-skin nb">
                            <span class="skin-name ">
                                <a href="#" class="s-skin-0">
                                    默认皮肤
                                </a>
                            </span>
                        </div>
                        <div class="setings-item blue-skin nb">
                            <span class="skin-name ">
                                <a href="#" class="s-skin-1">
                                    蓝色主题
                                </a>
                            </span>
                        </div>
                        <div class="setings-item yellow-skin nb">
                            <span class="skin-name ">
                                <a href="#" class="s-skin-3">
                                    黄色/紫色主题
                                </a>
                            </span>
                        </div>
                    </div>
                </div>
                <div id="tab-2" class="tab-pane">

                    <div class="sidebar-title">
                        <h3> <i class="fa fa-comments-o"></i> 最新通知</h3>
                        <small><i class="fa fa-tim"></i> 您当前有10条未读信息</small>
                    </div>

                    <div>

                        <div class="sidebar-message">
                            <a href="#">
                                <div class="pull-left text-center">
                                    <img alt="image" class="img-circle message-avatar" src="/uploadfile/342bd59b-edf4-48cf-aa27-d13e5a0b70df.jpeg">

                                    <div class="m-t-xs">
                                        <i class="fa fa-star text-warning"></i>
                                        <i class="fa fa-star text-warning"></i>
                                    </div>
                                </div>
                                <div class="media-body">

                                    据天津日报报道：瑞海公司董事长于学伟，副董事长董社轩等10人在13日上午已被控制。
                                    <br>
                                    <small class="text-muted">今天 4:21</small>
                                </div>
                            </a>
                        </div>
                    </div>

                </div>
                <div id="tab-3" class="tab-pane">

                    <div class="sidebar-title">
                        <h3> <i class="fa fa-cube"></i> 最新任务</h3>
                        <small><i class="fa fa-tim"></i> 您当前有14个任务，10个已完成</small>
                    </div>

                    <ul class="sidebar-list">
                        <li>
                            <a href="#">
                                <div class="small pull-right m-t-xs">9小时以后</div>
                                <h4>市场调研</h4> 按要求接收教材；

                                <div class="small">已完成： 22%</div>
                                <div class="progress progress-mini">
                                    <div style="width: 22%;" class="progress-bar progress-bar-warning"></div>
                                </div>
                                <div class="small text-muted m-t-xs">项目截止： 4:00 - 2015.10.01</div>
                            </a>
                        </li>
                    </ul>

                </div>
            </div>

        </div>
    </div>

    <!--右侧边栏结束-->
</div>
<!--右侧部分结束-->
@inject MsSystem.Web.Infrastructure.TokenClient tokenClient
@inject Microsoft.Extensions.Configuration.IConfiguration configuration
@section scripts{
    <script>
        const connection = new signalR.HubConnectionBuilder()
            .withUrl("@(configuration.GetSection("MsApplication").GetValue<string>("url") + "/hub/oa/messageHub")", {
                transport: signalR.HttpTransportType.LongPolling,
                accessTokenFactory: () => {
                    return "Authorization", getToken();
                }
            }).build();
        function getLocalTime(nS) {
            return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
        }
        connection.on("ReceiveMessage", function (data) {
            debugger;
            if (data.isSystem != 1) {
                data.isSystem = 0;
                data.link = '';
            }
            fillMsg(data);
        });
        connection.start().then(function () {
            //connection.invoke('InitMessage', $('img[name=userinfo]').attr('data-userid'));
            connection.invoke('InitMessage', 1);
        }).catch(function (err) {
            return console.error(err.toString());
            });
        connection.on("ReceiveAnyOne", data => {
            debugger;
        });

        function getToken() {
            return '@tokenClient.GetToken().Result';
        }

        function fillMsg(data) {
            document.getElementById('messageTipNums').textContent = parseInt(document.getElementById('messageTipNums').textContent) + 1;
            var html = '<li class="m-t-xs">';
            html += '<div class="dropdown-messages-box">';
            html += '<div class="media-body">';
            html += '<a data-id="' + data.id + '" data-issystem="' + data.isSystem + '" data-link="' + data.link + '">' + data.title + '</a>';
            html += '<small class="text-muted pull-right">' + $.unixToDate(data.createTime, true) + '</small>';
            html += '</div>';
            html += '</div>';
            html += '</li>';
            html += '<li class="divider"></li>';
            $('#messageTipContent').prepend(html);
            $('#messageTipAll').show();
        }

        $(function () {
            $('#messageTipContent').on('click', 'li.m-t-xs .dropdown-messages-box .media-body a', function () {
                var link = $(this).attr('data-link');
                var messageid = $(this).attr('data-id');
                $(this).parent().parent().parent().remove();
                removeMsg(messageid);
                document.getElementById('messageTipNums').textContent = parseInt(document.getElementById('messageTipNums').textContent) - 1;
                window.open(link);
            });
            function removeMsg(messageid) {
                var model = {
                    'MessageId': messageid
                };
                axios.post('/OA/Message/ReadMessageAsync', model).then(function (response) {
                    utils.permission.authResponse(response);
                });
            }
        });
    </script>
}